using System;
using System.IO;
using System.Text;

namespace stsdev {
  public class AssemblyInfoBuilder {
    public static void Create() {
      // ensure Properties directory exists
      if (!Directory.Exists("Properties")) {
        Directory.CreateDirectory("Properties");
      }
      // create AssemblyInfo.cs
      string FileName = @"Properties\AssemblyInfo.cs";
      FileStream stream = new FileStream(FileName,
                                         FileMode.Create,
                                         FileAccess.Write);

      StreamWriter writer = new StreamWriter(stream);
      string AssemblyInfo_cs_Content = Properties.Resources.AssemblyInfo_cs;
      // add AllowPartiallyTrustedCallers attribute for assemblies deployed to bin 
      string AsmAttributes = string.Empty;
      if (SolutionBuilder.DeploymentTarget == AssemblyDeploymentTarget.WebApplication) {
        AsmAttributes = "[assembly: System.Security.AllowPartiallyTrustedCallers()]";
      }
      AssemblyInfo_cs_Content = AssemblyInfo_cs_Content.Replace("@AsmAttributes", AsmAttributes);
      
      writer.Write(AssemblyInfo_cs_Content);
      writer.Dispose();
      stream.Dispose();

      ProjectFileBuilder.AddSourceFile(FileName);
    }
  }
}
